<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%
	String bathPath = request.getContextPath();
	pageContext.setAttribute("bathPath", bathPath);
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>登录页面</title>
<link href="${bathPath}/css/style1.css" rel="stylesheet" type="text/css" media="all"/>
<script type="text/javascript" src="${bathPath}/js/jquery-1.9.1.min.js" ></script>
<script type="text/javascript" src="${bathPath}/js/ajaxSessionOut.js" ></script>
<link rel="stylesheet" href="${bathPath}/css/cloudstyle.css">
<link href="${bathPath}/css/login.css" type="text/css" rel="stylesheet" />

<!-- layer -->
<link type="text/css" rel="stylesheet" href="${bathPath}/js/layer/skin/layer.css"/>
<script type="text/javascript" src="${bathPath}/js/layer/layer.js" ></script>
<style>
input::-webkit-input-placeholder {
	color:#fff;
}
</style>
<script type="text/javascript">

if(window != top){
	//session 失效 判断有没父页面，有，改变父页面地址
	top.location.href = location.href; 
}  
	

$(function(){
	
	$(".index_top_div").focus();
	
	$("#name").on("focus", function(){
		
		if($(this).attr("class") == "text_first"){
			
			$(this).removeClass("text_first");
			$(this).val("");
		}
		
	});
	
	$("#password").on("focus", function(){
		
		if($(this).attr("class") == "text_first"){
			
			$(this).parent().html("<input type='password' id='password' name='password' />");
			//$("#password").focus();
			document.getElementById("password").focus();
			//$(this).removeClass("text_first");
			//$(this).val("");
		}
		
	});
});

function login(){

	if($("#param .text_first").length > 0){
		return false;
	}
	
	// 准备参数
	var param = new Object();
	param.userName = $.trim($("#name").val());
	param.password = $.trim($("#password").val());
	
	if(param.userId == ""){

		layer.alert('用户名不可为空', {icon: 0});
		return false;
	}else if(param.password == ""){

		layer.alert('密码不可为空', {icon: 0});
		return false;
	}

	$.ajax({
		type:"POST",
		async:true,  //默认true,异步
		data:param,
		dataType:'text',
		url:"${bathPath}/login/tologin.action",
		success:function(data){
			
			if(data == "OK"){
				window.location.href = "${bathPath}/index/toIndexPage.action";
			}else if(data == "PASSWORD_ERROR"){

				layer.alert('密码错误', {icon: 2});
			}else if(data == "NO_EXIST"){

				layer.alert('用户不存在！', {icon: 2});
			}else{

				layer.alert('登陆失败！', {icon: 2});
			}
			
	    }
	});
}

function key_down(num){
	if(num == 13) {
		login();
	}
}
</script>
</head>
<body style="background:url(${bathPath}/image/LoginBg.png) no-repeat;">
	<form>
		<div class="shuru-1">
	    	<input type="text" id="name" style="border:0px;background:none;width:260px"/>
	   		<div class="clear"> </div>
	    </div>
	    <div class="shuru-2">
	    	<input type="password" id="password" name="password" style="border:0px;background:none;width:260px"/>
	    	<div class="clear"> </div>
	    </div>
	    <div class="queren">
				<input type="button" style="width:190px; height:190px;" id="login1" value="登录" onclick="login()">
		</div>
    </form>
</body>
</html>